package com.xajh.duoduo.environment;

import com.xajh.duoduo.config.NumConfig;
import com.xajh.duoduo.eunm.position.RolePosition;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

public class CurrentRolePosition {
    private static volatile AtomicReference<RolePosition> currentRolePosition = new AtomicReference<>(null);
    private static volatile Integer groupIndex;
    private static volatile Integer itemIndex;
    private static volatile Map<Integer, List<RolePosition>> rolesGroup = new HashMap<>();

    static {
        RolePosition[] values = RolePosition.values();
        int groupIndex = 0;
        List<RolePosition> item = new ArrayList<>();
        for(int i = 0; i < values.length ; i ++){
            item.add(values[i]);
            if(((i + 1) % NumConfig.roleNum) == 0 ){
                rolesGroup.put(groupIndex,item);
                item = new ArrayList<>();
                groupIndex ++;
            } else if(i == values.length -1){
                rolesGroup.put(groupIndex,item);
            }

        }
    }

    public static AtomicReference<RolePosition> getCurrentRolePosition() {
        return currentRolePosition;
    }

    public static void setCurrentRolePosition(AtomicReference<RolePosition> currentRolePosition) {
        CurrentRolePosition.currentRolePosition = currentRolePosition;
    }

    public static Integer getGroupIndex() {
        return groupIndex;
    }

    public static void setGroupIndex(Integer groupIndex) {
        CurrentRolePosition.groupIndex = groupIndex;
    }

    public static Integer getItemIndex() {
        return itemIndex;
    }

    public static void setItemIndex(Integer itemIndex) {
        CurrentRolePosition.itemIndex = itemIndex;
    }

    public static Map<Integer, List<RolePosition>> getRolesGroup() {
        return rolesGroup;
    }

}
